home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Human Interface Toolbox / HideMenuBar / HideMenuBar.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.6 KB  |  160 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        HideMenuBar.c
  3.  
  4.     Contains:    This snippet shows how to hide the menu bar by simply    
  5.                 creating a window with a visRgn that includes the        
  6.                 entire main screen's gray region and its menu bar.
  7.  
  8.     Written by: Edgar Lee    
  9.  
  10.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  11.  
  12.                 You may incorporate this Apple sample source code into your program(s) without
  13.                 restriction. This Apple sample source code has been provided "AS IS" and the
  14.                 responsibility for its operation is yours. You are not permitted to redistribute
  15.                 this Apple sample source code as "Apple sample source code" after having made
  16.                 changes. If you're going to re-distribute the source, we require that you make
  17.                 it clear in the source that the code was descended from Apple sample source
  18.                 code, but that you've made changes.
  19.  
  20.     Change History (most recent first):
  21.                 8/9/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  22.                                             HideMenuBar() Is now included in the OS in
  23.                                             MenusLib
  24.                 
  25.  
  26. */
  27.  
  28. #include <Quickdraw.h>
  29. #include <Dialogs.h>
  30. #include <Fonts.h>
  31. #include <Processes.h>
  32.  
  33.  
  34. /* Global Variable Definitions */
  35.  
  36. WindowPtr    gWindow;
  37.  
  38. void initMac();
  39.  
  40. //void HideMenuBar();
  41. void HideIt();
  42. void drawWindow();
  43. void doEventLoop();
  44.  
  45.  
  46. void main(void)
  47. {
  48.     initMac();
  49.     
  50.     HideMenuBar();
  51.     
  52.     doEventLoop();
  53. }
  54.  
  55. void initMac()
  56. {
  57.     MaxApplZone();
  58.  
  59.     InitGraf( &qd.thePort );
  60.     InitFonts();
  61.     InitWindows();
  62.     InitMenus();
  63.     TEInit();
  64.     InitDialogs( nil );
  65.     InitCursor();
  66.     FlushEvents( 0, everyEvent );
  67. }
  68.  
  69. /*void HideMenuBar()
  70. {
  71.     Rect    rect;
  72.     
  73.     gWindow = NewCWindow( 0L, &rect, "\p", false, plainDBox,
  74.                             (WindowPtr)-1L, true, 0L );                        
  75.     
  76.     MoveWindow( gWindow, qd.screenBits.bounds.left, qd.screenBits.bounds.top, true );
  77.     SizeWindow( gWindow, qd.screenBits.bounds.right - qd.screenBits.bounds.left,
  78.                         qd.screenBits.bounds.bottom - qd.screenBits.bounds.top, false );
  79.     
  80.     SetPort( gWindow );
  81.     ShowWindow( gWindow );
  82.     
  83.     TextMode( kFontIDGeneva );
  84.     TextSize( 9 );
  85.     TextMode( srcXor );
  86. }*/
  87.  
  88. void HideIt()
  89. {    
  90.     /****************************************************/
  91.     /* Set the window's visRgn to include the menu bar. */
  92.     /****************************************************/
  93.     
  94.     RectRgn( (*gWindow).visRgn, &qd.screenBits.bounds );
  95.     InvalRect( &qd.screenBits.bounds );
  96.     
  97.     /*************************************************/
  98.     /* Set the global MBarHeight to 0 to prevent any */
  99.     /*    other apps from writing to the menu bar.     */
  100.     /*************************************************/
  101.     
  102.     *((short *)0xbaa) = 0;
  103. }
  104.  
  105. void drawWindow()
  106. {
  107.     ForeColor( redColor );
  108.     PaintRect( &qd.screenBits.bounds );
  109.     
  110.     MoveTo( 15, 15 );
  111.     DrawString( "\pPress any key to quit." );
  112. }
  113.  
  114. void doEventLoop()
  115. {
  116.     EventRecord event;
  117.     WindowPtr   window;
  118.     short       clickArea;
  119.     Rect        screenRect;
  120.  
  121.     for (;;)
  122.     {
  123.         if (WaitNextEvent( everyEvent, &event, 0, nil ))
  124.         {
  125.             if (event.what == mouseDown)
  126.             {
  127.                 clickArea = FindWindow( event.where, &window );
  128.                 
  129.                 if (clickArea == inDrag)
  130.                 {
  131.                     screenRect = (**GetGrayRgn()).rgnBBox;
  132.                     DragWindow( window, event.where, &screenRect );
  133.                 }
  134.                 else if (clickArea == inContent)
  135.                 {
  136.                     if (window != FrontWindow())
  137.                         SelectWindow( window );
  138.                 }
  139.                 else if (clickArea == inGoAway)
  140.                     if (TrackGoAway( window, event.where ))
  141.                         return;
  142.             }
  143.             else if (event.what == keyDown || event.what == autoKey)
  144.                 ExitToShell();
  145.             else if (event.what == updateEvt)
  146.             {
  147.                 window = (WindowPtr)event.message;    
  148.                 SetPort( window );
  149.                 
  150.                 BeginUpdate( window );
  151.                 drawWindow();
  152.                 EndUpdate( window );
  153.             }
  154.             else if (event.what == activateEvt)
  155.             {
  156.                 HideIt();
  157.             }
  158.         }
  159.     }
  160. }